@extends('layouts.default') @section('main')
    <script type="text/javascript" src="{{URL::asset('js/')}}/ajaxfileupload.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
                            class="icon-home"></i> 首页</a>
                <a href="{{url('recommend/list')}}" class="tip-bottom">推荐管理</a>
                <a href="#" class="current">推荐信息编辑</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span9">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
                            <h5>推荐信息编辑</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form action="{{url('recommend/edit')}}" id="adForm" method="post" class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label">ID :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="id" value="{{$list->id}}" readonly="readonly"  />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>标题 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="subject" value="{{$list->subject}}"  />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>推荐的位置 :</label>
                                    <div class="controls">
                                        <select  name="position" class="span11" >
                                            <option value="">请选择推荐的位置</option>
                                            <option value="web_index" @if($list->position=='web_index')selected="selected" @endif>网站首页热门栏目</option>
                                            <option value="web_index_road" @if($list->position=='web_index_road')selected="selected" @endif>网站首页在路上栏目</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">图片大小说明 :</label>
                                    <div class="controls">
                                    <textarea style="width:600px" readonly>
首页热门排序1的图片尺寸为454*260象素，排序2/3的为200*110象素    在路上排序1的图片尺寸为462*272象素，排序2/3的为220*124象素
                                    </textarea>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">推荐图片 :</label>
                                    <div class="controls">
                                        <input type="hidden" class="span11" name="photo" value="{{$list->photo}}"
                                               placeholder="点击右边小图标上传" />
                                        <img src="{{getImage($list->photo)}}" width="120px" name="photo" height="120px"/>

                                        <a href="javascript:void(0);" id="uploadPhotoBtn"    onclick="javascript:openBrowse('uploadPhotoBtn','uploadPhoto');">点击上传(图片大小说明见上面)</a>
                                        <input type="file" id="uploadPhoto" style="display:none" name="myfile" size="10" onchange="fileUpload('uploadPhoto','photo')"/>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>所处的表格 :</label>
                                    <div class="controls">
                                        <select  id="table" name="table" class="span11" >
                                            <option value="">请选择所处的表格</option>
                                            <option value="activity" @if($list->table=='activity')selected="selected" @endif>活动</option>
                                            <option value="video" @if($list->table=='video')selected="selected" @endif>视频</option>
                                            {{--<option value="project" @if($list->table=='project')selected="selected" @endif>项目</option>--}}
                                            {{--<option value="article" @if($list->table=='article')selected="selected" @endif>文章</option>--}}
                                        </select>
                                    </div>
                                </div>


                                <div class="control-group">
                                    <label class="control-label">表格中记录的部分标题（供搜索） :</label>
                                    <div class="controls">
                                        <input type="text" class="span11"  name="title" placeholder="输入标题的一部分供模糊搜索，按下Enter键后执行搜索，搜索结果将出现在下面的多选框选项中" />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>表格中的记录的标题 :</label>
                                    <div class="controls">
                                        <select  name="post_id" id="post_id" class="span11" >
                                            <option value="{{$recommend->id}}">{{$recommend->subject}}</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>排序 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="sort" value="{{$list->sort}}"  />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">跳转地址 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="path_url" value="{{$list->path_url}}"  />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>是否生效 :</label>
                                    <div class="controls">
                                        <input type="radio"  name="status"  value="1" @if($list->status==1)checked="checked"@endif/>生效
                                        <input type="radio"  name="status"  value="0" @if($list->status==0)checked="checked"@endif/>暂不生效
                                    </div>
                                </div>
                                <div class="form-actions">
                                    <input type="hidden" class="span11" name="formType" value="edit" />
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                    <button type="button" id="doSave" class="btn btn-success">确认修改</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $("#doSave").click(function(){
            ajaxRequest($('#adForm').serializeArray(),$('#adForm').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });

        $("#table").change(function(){
            var html = '<option value="">请按上面输入框的说明生成选项</option>';
            $("#post_id").html(html);
        });


        $("input[name='title']").keydown(function(event){
            if(event.which == "13")
                var param = {};
            param['title'] = $(this).val();
            param['table'] = $("select[name='table']").val();
            ajaxRequest(param,'/recommend/search',function(data){
                if(data.status){
                    var html = '<option value="">请选择</option>';
                    $.each(data.message, function(i, n) {
                        html += "<option value='"+n.id+"'>"+n.subject+"</option>";
                    });
                    $("#post_id").html(html);
                        alert('恭喜，已经生成选项,请选择所需要的选项');
                }else{
                    var html = '<option value="">请按上面输入框的说明生成选项</option>';
                    $("#post_id").html(html);
                    alert(data.message);
                }
            });
        });
    </script>
@stop
